package com.webproject.core;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.webproject.entity.sysManager.SysLog;
import com.webproject.entity.sysManager.User;
import com.webproject.service.sysManager.LogManagerService;

/**
 * Recroding user operation
 * @author lijiang
 * 
 */
public class LogInterceptor extends AbstractInterceptor {
	private LogManagerService logManagerService;
	public LogManagerService getLogManagerService() {
		return logManagerService;
	}
	public void setLogManagerService(LogManagerService logManagerService) {
		this.logManagerService = logManagerService;
	}
	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		System.out.println("current Method:"+arg0.getInvocationContext().getName());
		SysLog sysLog=new SysLog();
		sysLog.setOperation(arg0.getInvocationContext().getName());
		Object obj=ServletActionContext.getRequest().getSession().getAttribute("user");
		if(obj!=null){
			sysLog.setUserId(String.valueOf(((User)obj).getId()));
		}
		logManagerService.saveSysLog(sysLog);
		return arg0.invoke();
	}
}
